#include <sys/types.h>  /* for type definitions */
#include <sys/socket.h> /* for socket API calls */
#include <netinet/in.h> /* for address structs */
#include <arpa/inet.h>  /* for sockaddr_in */
#include <stdio.h>      /* for printf() and fprintf() */
#include <stdlib.h>     /* for atoi() */
#include <string.h>     /* for strlen() */
#include <unistd.h>     /* for close() */
#include <pthread.h>
#include <messages.h>

#define MAXBUFFSIZE 1500

char IP[PHILOSOFERSNUMBER][16];
int PORTS[PHILOSOFERSNUMBER];



int main(int argc, char** argv)
{
  int lc = 0, ts;
  readPhilosofersInfo();


  pthread_t hl;
  pthread_create(&hl, 0, helper, 0);

  pthread_t ph;
  pthread_create(&ph, 0, philosofer, 0);

}

void readPhilosofersInfo()
{
    //TODO lê números de IP e porta de todos os processos
}

void *philosofer()
{
    int lc = 0, ts;
    
    //ask helper to do V(s)
    //send semop[i](i, reqV, lc); lc++;
    
    //ask helper do do P(s), then wait for permission
    //send semop[i](i, reqP, lc); lc++;
    //receive go[i]; lc = max(lc, ts+1); lc++;
}

void *helper()
{

}
